package com.spring.bean.demo2;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试 Bean 实例化的三种方式
 */
public class SpringDemo2 {
    @Test
    /**
     * 无参构造方法实例化 Bean 测试
     */
    public void demo1 () {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        Bean1 bean1 = (Bean1) applicationContext.getBean("bean1");
    }

    @Test
    /**
     * 静态工厂实例化 Bean 测试
     */
    public void demo2 () {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        Bean2 bean2 = (Bean2) applicationContext.getBean("bean2");
    }

    @Test
    /**
     * 实例工厂实例化 Bean 测试
     */
    public void demo3 () {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        Bean3 bean3 = (Bean3) applicationContext.getBean("bean3");
    }
}
